package shapewar.engine.ext;

import android.graphics.Color;
import shapewar.conf.Conf;
import shapewar.engine.intefac.ITank;
import shapewar.engine.intefac.IView;
import shapewar.engine.presenter.Presenter;
import shapewar.view.indvidul.SkillColderView;
import shapewar.view.myview.MyButton;
import shapewar.view.tank.TankView;

public class SkillColder {
	public float width = Conf.frame_width;
	public float height = Conf.frame_height;
	public float left = Conf.frame_width - Conf.dip2px(55);
	public float top = Conf.frame_height - Conf.dip2px(55);
	private SkillColderView scv;
	int t_fire = 0,t_flash = 0;
	boolean isPlayer = false;
	boolean fireAdmit = true;
	boolean flashAdmit = true;
	private ITank tank;
	public SkillColder(ITank tank){
		this.tank = tank;
	}
	public void cold(){
		//fire cold
		if(t_fire>Conf.fire_cold_time){
			fireAdmit = true;
		}else{
			t_fire++;
			if(scv!=null)
				scv.invalidate();
		}
		//flash cold
		if(t_flash>Conf.flash_cold_time){
			flashAdmit = true;
			if(scv!=null)
				if(scv.pst.ect.flashBtn!=null)
					scv.pst.ect.flashBtn.enable(true);
		}else{
			t_flash++;
			if(scv!=null)
				scv.invalidate();
			if(scv!=null)
				if(scv.pst.ect.flashBtn!=null)
					scv.pst.ect.flashBtn.enable(false);
		}
		
		if(super_time){
			if(t_super_time++<Conf.super_time){
				if(t_super_time%10==0)
					((TankView)(tank.getInstance().getView())).setColor(Color.rgb((int)(Math.random()*255), (int)(Math.random()*255), (int)(Math.random()*255)));
			}else{
				super_time = false;
				((TankView)(tank.getInstance().getView())).setColor(Conf.tank_color);
			}
		}
		
	}
	
	public boolean fireAdmit(){
		return fireAdmit;
	}
	public boolean flashAdmit(){
		return flashAdmit;
	}
	
	public int getFireColdFinishPercent(){
		return (int)(100f*t_fire/Conf.fire_cold_time);
	}
	
	public int getFlashColdFinishPercent(){
		return (int)(100f*t_flash/Conf.flash_cold_time);
	}
	
	public void fired(){
		t_fire = 0;
		fireAdmit = false;
	}
	
	public void flashed(){
		t_flash = 0;
		flashAdmit = false;
	}
	
	public void setPlayer(Presenter pst,boolean isPlayer){
		if(isPlayer){
			this.isPlayer = true;
			scv = new SkillColderView(pst, this);
			pst.bridge.addView(scv);
		}else{
			scv = null;
		}
	}
	
	public void removeColderView(Presenter pst) {
		if(isPlayer)
			pst.bridge.removeView(scv);
	}
	
	//Super Time
	public boolean super_time = true;
	int t_super_time = 0;
	public void supertime() {
		super_time = true;
	}
}